#!/usr/bin/python3
# -*- coding: UTF-8 -*-

import os
from gitlab_map import site_map
import config as c

def git_clone(filepath, git_flow_open):
    domain_list = c.dirname_list
    gitflow = c.gitflow_list
    domain = []
    if git_flow_open:
        for i in domain_list:
            for k in gitflow:
                if k == i:
                    domain.append(k)
    else:
        for i in domain_list:
            for k in gitflow:
                if k == i:
                    domain_list.remove(k)
    domain = domain_list
    for i in domain:
        name = i.lower()
        print(name)
        fi = site_map[name]
        fi_d = filepath
        try:
            cmd = "cd /d %s && git clone %s " % (fi_d,fi)
            print("cmd=", cmd)
            os.system(cmd)
            if git_flow_open:
                f = fi.split('/')[1][:-4]
                cmd = "cd /d %s\%s && git checkout -b develop && git branch --set-upstream-to=origin/develop develop && git checkout master && git checkout -b hotfix/%s" % (fi_d, f, c.hot_fix_name)
                print("cmd=", cmd)
                os.system(cmd)
            print("-------------done--------------")
        except:
            print(fi + ' ***** 拉取失败 *****')

if __name__ == "__main__":
    batch_git_path = c.batch_git_path
    git_clone(batch_git_path, c.git_flow_check)
